#!/bin/bash
LOG_START_TIME = `date + "% Y% m% d% H% M% S"`
BACKUP_DIR = ~/backup
BACKUP_LOG = " $ BACKUP_DIR/ $ {LOG_START_TIME}.log"
function write_log()
{
log_time = `date + "% Y-% m-% d-% H-% M-% S"`
backup_file_name = $ 2
err_msg = " $ log_time ERROR in backup file/directory($backup_file_name)"
suc_msg = " $ log_time SUCCESS in backup file/directory($backup_file_name)" 
if[ $ 1 -eq 0];then
echo $ suc_msg
echo $ suc_msg >> $BACKUP_LOG
else
echo $ err_msg
echo $ err_msg >> $BACKUP_LOG
fi
}
function back_file()
{
cp -fr $ 1 $ BACKUP_DIR > /dev/null 2 > &1
write_log $ ? $ 1
}
function create_log_file()
{
if [ ! -e $ BACKUP_DIR ] ;then
mkdir $ BACKUP_DIR
fi
if [ -e $ BACKUP_DIR ] ;then
rm -f $ BACKUP_LOG
fi
touch $ BACKUP_LOG
}
clear
echo "Please write which file You want to backup"
create_log_file
for file in $ @
do
backup_file $ file
done
echo "Over!!!"
